/** 
 * @author Huang RuiGuang
 * @date 2008/12/1
 *
 * Herm library
 * Copyright (c) 2008 by Huang RuiGuang(daemon.huang@gmail.com)
 *
 * Permission to use, copy, modify, distribute and sell this software.
 */

#ifndef HERM_FRAMEWORK_ACCEPT_HANDLER_H
#define HERM_FRAMEWORK_ACCEPT_HANDLER_H

#include "herm/base/socket/socket_handler.h"
#include "herm/base/network/interface.h"

namespace herm{
	class Multiplexor;
	class Address;
	class Acceptor;
    class Buffer;
}

class AcceptHandler : public herm::ISockHandler
{
public:
	AcceptHandler();
	virtual ~AcceptHandler();

	void Close();
protected:
	void Reset(const herm::Address& addr, herm::Multiplexor* multiplexor, int acceptQueueSize);
private: 
	virtual herm::Handle OnGetHandle() const;
	virtual int OnReceive(int);
	virtual int OnSend(int);
	virtual void OnError(int stateType, int stateCode);

protected:
	herm::uint32_t m_state;
	herm::Buffer* m_acceptSocks;
private:
	herm::Multiplexor* m_multiplexor;
	herm::Acceptor* m_acceptor;
};

#endif
